{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from modelscope.msdatasets import MsDataset\n",
    "from modelscope.utils.constant import DownloadMode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-08-06 23:41:29,591 - modelscope - WARNING - Reusing dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:41:29,591 - modelscope - INFO - Generating dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:41:29,592 - modelscope - INFO - Loading meta-data file ...\n",
      "276it [00:00, 1364.31it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100% {'image:FILE': '/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files/extracted/bc5712030f447cf9f432ea41ef6ea0ae14bb12e6fa549d38d259a7bc130d65ba/train/cat/Sphynx_159_jpg.rf.022528b23ac690c34ad5d109c1782079.jpg', 'category': 0}\n"
     ]
    }
   ],
   "source": [
    "ms_train_dataset = MsDataset.load(\n",
    "    \"cats_and_dogs\", namespace=\"tany0699\",\n",
    "    subset_name=\"default\", split=\"train\"\n",
    ") # 加载训练集\n",
    "print(next(iter(ms_train_dataset)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-08-06 23:43:08,398 - modelscope - WARNING - Reusing dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:43:08,399 - modelscope - INFO - Generating dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:43:08,399 - modelscope - INFO - Loading meta-data file ...\n",
      "  1%|▏         | 71/4974 [00:00<00:00, 111283.85it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100% {'image:FILE': '/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files/extracted/69e4bbc7b1305e69fd4abed945da737a667815c44cc20a48d6ce6f9d6e0c34b3/val/cat/Persian_13_jpg.rf.dd6ccb81649242fcc8a22fd4ddbfbab7.jpg', 'category': 0}\n"
     ]
    }
   ],
   "source": [
    "ms_val_dataset = MsDataset.load(\n",
    "    \"cats_and_dogs\", namespace=\"tany0699\",\n",
    "    subset_name=\"default\", split=\"validation\"\n",
    ")# 加载验证集\n",
    "print(next(iter(ms_val_dataset)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入MsDataset类，用于加载ModelScope数据集\n",
    "from modelscope.msdatasets import MsDataset\n",
    "# 导入DownloadMode常量，通常用于指定数据集的下载模式\n",
    "from modelscope.utils.constant import DownloadMode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-08-06 23:48:57,585 - modelscope - WARNING - Reusing dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:48:57,586 - modelscope - INFO - Generating dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:48:57,586 - modelscope - INFO - Reusing cached meta-data file: /root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files/f393e0258171c4a8b950cbb19d29e9b7\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'image:FILE': '/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files/extracted/bc5712030f447cf9f432ea41ef6ea0ae14bb12e6fa549d38d259a7bc130d65ba/train/cat/Sphynx_159_jpg.rf.022528b23ac690c34ad5d109c1782079.jpg', 'category': 0}\n"
     ]
    }
   ],
   "source": [
    "ms_train_dataset = MsDataset.load(\n",
    "    \"cats_and_dogs\", namespace=\"tany0699\",\n",
    "    subset_name=\"default\", split=\"train\"\n",
    ")\n",
    "print(next(iter(ms_train_dataset)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-08-06 23:49:04,351 - modelscope - WARNING - Reusing dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:49:04,352 - modelscope - INFO - Generating dataset dataset_builder (/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files)\n",
      "2024-08-06 23:49:04,352 - modelscope - INFO - Reusing cached meta-data file: /root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files/ffaacde1d8728794192f1048d50871eb\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'image:FILE': '/root/.cache/modelscope/hub/datasets/tany0699/cats_and_dogs/master/data_files/extracted/69e4bbc7b1305e69fd4abed945da737a667815c44cc20a48d6ce6f9d6e0c34b3/val/cat/Persian_13_jpg.rf.dd6ccb81649242fcc8a22fd4ddbfbab7.jpg', 'category': 0}\n"
     ]
    }
   ],
   "source": [
    "ms_val_dataset = MsDataset.load(\n",
    "    \"cats_and_dogs\", namespace=\"tany0699\",\n",
    "    subset_name=\"default\", split=\"validation\"\n",
    ")# 加载验证集\n",
    "print(next(iter(ms_val_dataset)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "from torchvision import transforms\n",
    "from PIL import Image\n",
    "from torch.utils.data import Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义一个自定义数据集类DatasetLoader，继承torch.utils.data.Dataset\n",
    "class DatasetLoader(Dataset):\n",
    "    # 初始化方法\n",
    "    def __init__(self, data):\n",
    "        self.data = data\n",
    "    \n",
    "    # 定义一个图片预处理方法\n",
    "    def preprocess_image(self, image_path):\n",
    "        image = Image.open(image_path)\n",
    "        image_transform = transforms.Compose([\n",
    "            transforms.Resize((256, 256)),\n",
    "            transforms.ToTensor(),\n",
    "            transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # 标准化图像\n",
    "        ])\n",
    "        # 应用图像变换并返回结果\n",
    "        return image_transform(image)\n",
    "    \n",
    "    # 重写__gettitem__方法，使其能够根据索引返回单个样本\n",
    "    def __getitem__(self, index):\n",
    "        # 根据索引从数据集中获取图像路径\n",
    "        image_path, label = self.data[index]['image:FILE'], self.data[index]['category']\n",
    "        # 根据图像路径获取图像\n",
    "        image = self.preprocess_image(image_path)\n",
    "        # 返回图像和标签\n",
    "        return image, int(label)\n",
    "    \n",
    "    # 重写__len__方法，使其能够返回数据集大小\n",
    "    def __len__(self):\n",
    "        return len(self.data)\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_train = DatasetLoader(ms_train_dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 模型的设计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torchvision\n",
    "from torchvision.models import ResNet50_Weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Downloading: \"https://download.pytorch.org/models/resnet50-11ad3fa6.pth\" to /root/.cache/torch/hub/checkpoints/resnet50-11ad3fa6.pth\n",
      "100%|██████████| 97.8M/97.8M [00:07<00:00, 13.2MB/s]\n"
     ]
    }
   ],
   "source": [
    "# 加载预训练的Resnet50模型\n",
    "model = torchvision.models.resnet50(weights=ResNet50_Weights.IMAGENET1K_V2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torchvision\n",
    "from torchvision.models import ResNet50_Weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载预训练的Resnet50模型\n",
    "model = torchvision.models.resnet50(weights=ResNet50_Weights.IMAGENET1K_V2)\n",
    "num_classes = 2\n",
    "\n",
    "# 将全连接层的输出维度替换为num_classes\n",
    "in_features = model.fc.in_features\n",
    "model.fc = torch.nn.Linear(in_features, num_classes)\n",
    "# device = \"cuda\"\n",
    "device = \"cpu\"\n",
    "model.to(device)\n",
    "num_epochs = 20\n",
    "lr = 1e-5\n",
    "batch_size = 16\n",
    "criterion = torch.nn.CrossEntropyLoss()\n",
    "optimizer = torch.optim.Adam(model.parameters(), lr=lr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pytorch模型训练的基本流程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import swanlab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "num_epochs = 20\n",
    "lr = 1e-4\n",
    "batch_size = 8\n",
    "num_classes = 2\n",
    "device = \"cpu\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Project name `第3章基于gradio的云上自托管ChatGLM部署实战` is invalid, which must be 0-9, a-z, A-Z, _ , -, +, .",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mswanlab\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minit\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m      2\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;66;43;03m# 设置实验名\u001b[39;49;00m\n\u001b[1;32m      3\u001b[0m \u001b[43m    \u001b[49m\u001b[43mexperiment_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mResNet50\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m      4\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;66;43;03m# 设置实验介绍\u001b[39;49;00m\n\u001b[1;32m      5\u001b[0m \u001b[43m    \u001b[49m\u001b[43mdescription\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mclassification\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m      6\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;66;43;03m# 记录超参数\u001b[39;49;00m\n\u001b[1;32m      7\u001b[0m \u001b[43m    \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\n\u001b[1;32m      8\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mresnet50\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m      9\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43moptim\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mAdam\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m     10\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlr\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43mlr\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m     11\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mbatch_size\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43mbatch_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m     12\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mnum_epochs\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43mnum_epochs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m     13\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mnum_class\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43mnum_classes\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m     14\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdevice\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43mdevice\u001b[49m\n\u001b[1;32m     15\u001b[0m \u001b[43m    \u001b[49m\u001b[43m}\u001b[49m\n\u001b[1;32m     16\u001b[0m \u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/miniconda3/envs/py311/lib/python3.11/site-packages/swanlab/data/sdk.py:164\u001b[0m, in \u001b[0;36minit\u001b[0;34m(project, workspace, experiment_name, description, config, logdir, suffix, mode, load, public, **kwargs)\u001b[0m\n\u001b[1;32m    162\u001b[0m     public \u001b[38;5;241m=\u001b[39m _load_data(load_data, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprivate\u001b[39m\u001b[38;5;124m\"\u001b[39m, public)\n\u001b[1;32m    163\u001b[0m operator, c \u001b[38;5;241m=\u001b[39m _create_operator(mode, public)\n\u001b[0;32m--> 164\u001b[0m project \u001b[38;5;241m=\u001b[39m \u001b[43m_check_proj_name\u001b[49m\u001b[43m(\u001b[49m\u001b[43mproject\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mproject\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbasename\u001b[49m\u001b[43m(\u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgetcwd\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m  \u001b[38;5;66;03m# 默认实验名称为当前目录名\u001b[39;00m\n\u001b[1;32m    165\u001b[0m exp_num \u001b[38;5;241m=\u001b[39m SwanLabRunOperator\u001b[38;5;241m.\u001b[39mparse_return(\n\u001b[1;32m    166\u001b[0m     operator\u001b[38;5;241m.\u001b[39mon_init(project, workspace, logdir\u001b[38;5;241m=\u001b[39mlogdir), key\u001b[38;5;241m=\u001b[39mc\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__str__\u001b[39m() \u001b[38;5;28;01mif\u001b[39;00m c \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m    167\u001b[0m )\n\u001b[1;32m    168\u001b[0m \u001b[38;5;66;03m# 初始化confi参数\u001b[39;00m\n",
      "File \u001b[0;32m~/miniconda3/envs/py311/lib/python3.11/site-packages/swanlab/data/sdk.py:49\u001b[0m, in \u001b[0;36m_check_proj_name\u001b[0;34m(name)\u001b[0m\n\u001b[1;32m     30\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_check_proj_name\u001b[39m(name: \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m     31\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"检查项目名称是否合法，如果不合法则抛出ValueError异常\u001b[39;00m\n\u001b[1;32m     32\u001b[0m \u001b[38;5;124;03m    项目名称必须是一个非空字符串，长度不能超过255个字符\u001b[39;00m\n\u001b[1;32m     33\u001b[0m \n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     47\u001b[0m \u001b[38;5;124;03m        项目名称不合法\u001b[39;00m\n\u001b[1;32m     48\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m---> 49\u001b[0m     _name \u001b[38;5;241m=\u001b[39m \u001b[43mcheck_proj_name_format\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     50\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(name) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mlen\u001b[39m(_name):\n\u001b[1;32m     51\u001b[0m         swanlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproject name is too long, auto cut to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[0;32m~/miniconda3/envs/py311/lib/python3.11/site-packages/swanlab/data/formater.py:123\u001b[0m, in \u001b[0;36mcheck_proj_name_format\u001b[0;34m(name, auto_cut)\u001b[0m\n\u001b[1;32m    121\u001b[0m max_len \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m100\u001b[39m\n\u001b[1;32m    122\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m check_string(name) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m re\u001b[38;5;241m.\u001b[39mmatch(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m^[0-9a-zA-Z_\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m-+.]+$\u001b[39m\u001b[38;5;124m\"\u001b[39m, name):\n\u001b[0;32m--> 123\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mProject name `\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m` is invalid, which must be 0-9, a-z, A-Z, _ , -, +, .\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m    124\u001b[0m name \u001b[38;5;241m=\u001b[39m name\u001b[38;5;241m.\u001b[39mstrip()\n\u001b[1;32m    125\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _auto_cut(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproject\u001b[39m\u001b[38;5;124m\"\u001b[39m, name, max_len, auto_cut)\n",
      "\u001b[0;31mValueError\u001b[0m: Project name `第3章基于gradio的云上自托管ChatGLM部署实战` is invalid, which must be 0-9, a-z, A-Z, _ , -, +, ."
     ]
    }
   ],
   "source": [
    "swanlab.init(\n",
    "    # 设置实验名\n",
    "    experiment_name=\"ResNet50\",\n",
    "    # 设置实验介绍\n",
    "    description = \"classification\",\n",
    "    # 记录超参数\n",
    "    config = {\n",
    "        \"model\":\"resnet50\",\n",
    "        \"optim\":\"Adam\",\n",
    "        \"lr\":lr,\n",
    "        \"batch_size\":batch_size,\n",
    "        \"num_epochs\":num_epochs,\n",
    "        \"num_class\":num_classes,\n",
    "        \"device\":device\n",
    "    }\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py311",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
